package com.competition.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.competition.entity.EquipmentLeasing;
import com.competition.mapper.EquipmentAuditMapper;
import com.competition.mapper.EquipmentLeasingMapper;
import com.competition.resp.ResponseResult;
import com.competition.service.EquipmentLeasingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("/equipment")
public class EquipmentLeasingController {

    @Autowired
    private EquipmentLeasingService equipmentLeasingService;
    @Autowired
    private EquipmentLeasingMapper equipmentLeasingMapper;

    @GetMapping("/getEquipment")//获取全部设备
    public ResponseResult getEquipment(@RequestParam("current") int current){

        try {
            Page<EquipmentLeasing> page = new Page<>(current,5);//固定煤业5条
            QueryWrapper queryWrapper = new QueryWrapper();
            queryWrapper.gt("equipment_inventory",0);
            Page<EquipmentLeasing> page1 = equipmentLeasingMapper.selectPage(page, queryWrapper);
            return new ResponseResult(200,"获取成功",page1);
        } catch (Exception e) {
            e.printStackTrace();
            return  new ResponseResult(300,"获取失败",null);
        }

    }
    @GetMapping("/getEquipmentById")//获取对应的设备id信息
    public ResponseResult getEquipmentById(@RequestParam("equipmentId") String equipmentId){
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("equipment_id",equipmentId);
        EquipmentLeasing one = null;
        try {
            one = equipmentLeasingService.getOne(queryWrapper);
            return new ResponseResult(200,"获取成功",one);
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult(300,"获取失败",null);
        }

    }




}
